package com.bocai.kelalacar.ui.car.set.ada;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bocai.kelalacar.R;
import com.bocai.kelalacar.bean.ApplyWayBean;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by yuanfei on 2017/6/23.
 */

public class WithdrawAda extends BaseAdapter {

    private Context mContext;
    private ApplyWayBean bean;

    public WithdrawAda(Context mContext,ApplyWayBean bean){
        this.mContext = mContext;
        this.bean = bean;
    }

    @Override
    public int getCount() {
        int index = 0;
        if (bean == null){
            return 0;
        }else {
            if (bean.getAlipay()!=null&& !TextUtils.isEmpty(bean.getAlipay().getWayId())){
                index = index + 1;
            }
            if (bean.getWeixin()!=null&& !TextUtils.isEmpty(bean.getWeixin().getWayId())){
                index = index + 1;
            }
            if (bean.getBankCard()!=null){
                index = index + bean.getBankCard().size();
            }
        }
        return index;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_withdraw, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        if (bean.getBankCard().size()>position){
            viewHolder.imgType.setImageDrawable(mContext.getResources().getDrawable(R.mipmap.yinlian1));
            viewHolder.tvType.setVisibility(View.GONE);
            String bb = bean.getBankCard().get(position).getAccount().substring(bean.getBankCard().get(position).getAccount().length()-4,bean.getBankCard().get(position).getAccount().length());
//            viewHolder.tvAccount.setText("**** **** **** "+bb);
            viewHolder.tvAccount.setText("尾号 "+bb+" 储蓄卡");
        }else if (bean.getBankCard().size() + 1>position){
            if (bean.getAlipay()!=null&&!TextUtils.isEmpty(bean.getAlipay().getWayId())){
                viewHolder.imgType.setImageDrawable(mContext.getResources().getDrawable(R.mipmap.zhifub));
                viewHolder.tvType.setText("支付宝");
                viewHolder.tvAccount.setText("支付宝账户："+bean.getAlipay().getAccount());
            }else {
                viewHolder.imgType.setImageDrawable(mContext.getResources().getDrawable(R.mipmap.weichat));
                viewHolder.tvType.setText("微信");
                viewHolder.tvAccount.setText("微信账号："+bean.getAlipay().getAccount());
            }
        }else {
            viewHolder.imgType.setImageDrawable(mContext.getResources().getDrawable(R.mipmap.weichat));
            viewHolder.tvType.setText("微信");
            viewHolder.tvAccount.setText("微信账号："+bean.getAlipay().getAccount());
        }
        return convertView;
    }
    static class ViewHolder {
        @BindView(R.id.img_type)
        ImageView imgType;
        @BindView(R.id.tv_type)
        TextView tvType;
        @BindView(R.id.tv_account)
        TextView tvAccount;
        @BindView(R.id.img_check)
        ImageView imgCheck;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
